package edu.sdwu.liqing.qasystem.model;

import lombok.Data;

@Data
public class Response<T> {

    //状态码
    private Integer code;

    private String message;

    private T body;

    public static <T> Response<T> ok(T body) {
        Response<T> response = new Response<>();
        response.setCode(200);
        response.setMessage("成功");
        response.setBody(body);
        return response;
    }

    public static <T> Response<T> error(T body) {
        Response<T> response = new Response<>();
        response.setCode(400);
        response.setMessage("操作失败");
        response.setBody(body);
        return response;
    }


    public static <T> Response<T> create(Integer code, String message, T body) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        response.setBody(body);
        return response;
    }

    @SuppressWarnings("unchecked")
    public static <T> Response<T> ok(String message) {
        Response response = new Response<>();
        response.setCode(200);
        response.setMessage(message);
        response.setBody(null);
        return response;
    }

    @SuppressWarnings("unchecked")
    public static <T> Response<T> error(String message) {
        Response response = new Response<>();
        response.setCode(500);
        response.setMessage(message);
        response.setBody(null);
        return response;
    }
}
